package net.learn.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.learn.framework.common.page.PageResult;
import net.learn.framework.common.utils.Result;
import net.learn.system.query.SysAnswerQuery;
import net.learn.system.query.SysFillQuery;
import net.learn.system.service.SysAnswerService;
import net.learn.system.service.SysFillService;
import net.learn.system.vo.SysAnswerVO;
import net.learn.system.vo.SysFillVO;
import net.learn.system.vo.SysJudgeVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 简答管理
 */
@RestController
@RequestMapping("sys/answer")
@Tag(name="简答管理")
@AllArgsConstructor
public class SysAnswerController {

    @Autowired
    private final SysAnswerService answerService;

    @GetMapping("getAnswer")
    @Operation(summary = "分页获取简答题列表")
    public Result<PageResult<SysAnswerVO>> getFill(@Valid SysAnswerQuery query){
        PageResult<SysAnswerVO> page = answerService.qryAnswerListPage(query);

        return Result.ok(page);
    }
    @PostMapping("getAnswerList")
    @Operation(summary = "获取简答列表")
    public Result<List<SysAnswerVO>> getAnswerList(@RequestBody SysAnswerQuery query){
        List<SysAnswerVO> list = answerService.qryAnswerList();

        return Result.ok(list);
    }
    @PostMapping("getPaperAnswerList")
    @Operation(summary = "获取试卷题库列表")
    public Result<List<SysAnswerVO>> getPaperAnswerList(@RequestBody SysAnswerQuery query){
        List<SysAnswerVO> list = answerService.qryPaperAnswerList(query);

        return Result.ok(list);
    }
    @PostMapping("getAnswerRandList")
    @Operation(summary = "获取随机简答题")
    public Result<List<SysAnswerVO>> getAnswerRandList(@RequestBody SysAnswerQuery query){
        List<SysAnswerVO> list = answerService.qryAnswerRandList(query);

        return Result.ok(list);
    }
    @PostMapping("getPaperAnswerCondition")
    @Operation(summary = "获取正在考试试卷题库列表")
    public Result<List<SysAnswerVO>> getPaperAnswerCondition(@RequestBody SysAnswerQuery query){
        List<SysAnswerVO> list = answerService.qryPaperAnswerCondition(query);

        return Result.ok(list);
    }
    @PostMapping("/updateAnswer")
    @Operation(summary = "修改简答")
    public Result<String> updateJudge(@RequestBody @Valid SysAnswerVO vo){
        answerService.updateAnswer(vo);

        return Result.ok();
    }
    @PostMapping("save")
    @Operation(summary = "新增简答")
    public Result<String> save(@RequestBody SysAnswerVO vo){
        answerService.addAnswer(vo);

        return Result.ok();
    }

    @DeleteMapping
    @Operation(summary = "删除")
    public Result<String> deleteById(@RequestBody List<Long> idList){

        answerService.delete(idList);
        return Result.ok();
    }
}

